-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #328 from Team-Ampersand/develop
Develop
- Loading branch information
Showing
12 changed files
with
189 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
src/main/java/com/server/Dotori/domain/board/controller/common/CommonBoardController.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/com/server/Dotori/domain/main_page/controller/BoardAlarmController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.server.Dotori.domain.main_page.controller; | ||
|
||
import com.server.Dotori.domain.main_page.service.BoardAlarmService; | ||
import com.server.Dotori.global.response.ResponseService; | ||
import com.server.Dotori.global.response.result.SingleResult; | ||
import io.swagger.annotations.ApiImplicitParam; | ||
import io.swagger.annotations.ApiImplicitParams; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/v1/board") | ||
public class BoardAlarmController { | ||
|
||
private final BoardAlarmService boardService; | ||
private final ResponseService responseService; | ||
|
||
@GetMapping(value = "/alarm") | ||
@ResponseStatus( HttpStatus.OK ) | ||
@ApiImplicitParams({ | ||
@ApiImplicitParam(name = "Authorization", value = "로그인 성공 후 access_token", required = true, dataType = "String", paramType = "header"), | ||
@ApiImplicitParam(name = "RefreshToken", value = "로그인 성공 후 refresh_token", required = false, dataType = "String", paramType = "header") | ||
}) | ||
public SingleResult getBoardAlarmInfo() { | ||
return responseService.getSingleResult(boardService.getBoardAlarmInfo()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/server/Dotori/domain/main_page/dto/BoardAlarmDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.server.Dotori.domain.main_page.dto; | ||
|
||
import com.server.Dotori.domain.member.enumType.Role; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
@Getter @Builder | ||
@NoArgsConstructor(access = PROTECTED) @AllArgsConstructor | ||
public class BoardAlarmDto { | ||
|
||
private Long id; | ||
private String title; | ||
private List<Role> writerRole; | ||
private LocalDate lastBoardWriteDate; | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/server/Dotori/domain/main_page/service/BoardAlarmService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.server.Dotori.domain.main_page.service; | ||
|
||
import com.server.Dotori.domain.main_page.dto.BoardAlarmDto; | ||
|
||
public interface BoardAlarmService { | ||
|
||
BoardAlarmDto getBoardAlarmInfo(); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/server/Dotori/domain/main_page/service/Impl/BoardAlarmServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.server.Dotori.domain.main_page.service.Impl; | ||
|
||
import com.server.Dotori.domain.board.Board; | ||
import com.server.Dotori.domain.main_page.dto.BoardAlarmDto; | ||
import com.server.Dotori.domain.board.repository.BoardRepository; | ||
import com.server.Dotori.domain.main_page.service.BoardAlarmService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class BoardAlarmServiceImpl implements BoardAlarmService { | ||
|
||
private final BoardRepository boardRepository; | ||
|
||
/** | ||
* 새로운 공지사항 등록 여부를 판단할 수 있는 서비스 로직 (로그인 된 유저 사용가능) | ||
* @return board count | ||
* @author 배태현 | ||
*/ | ||
@Override | ||
public BoardAlarmDto getBoardAlarmInfo() { | ||
Board lastWriteBoard = boardRepository.findTop1ByOrderByCreatedDateDesc(); | ||
|
||
return BoardAlarmDto.builder() | ||
.id(lastWriteBoard.getId()) | ||
.title(lastWriteBoard.getTitle()) | ||
.writerRole(lastWriteBoard.getMember().getRoles()) | ||
.lastBoardWriteDate(lastWriteBoard.getCreatedDate().toLocalDate()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...st/java/com/server/Dotori/domain/main_page/board_alarm/service/BoardAlarmServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.server.Dotori.domain.main_page.board_alarm.service; | ||
|
||
import com.server.Dotori.domain.board.dto.BoardDto; | ||
import com.server.Dotori.domain.board.service.BoardService; | ||
import com.server.Dotori.domain.main_page.dto.BoardAlarmDto; | ||
import com.server.Dotori.domain.main_page.service.BoardAlarmService; | ||
import com.server.Dotori.domain.member.dto.MemberDto; | ||
import com.server.Dotori.domain.member.enumType.Gender; | ||
import com.server.Dotori.domain.member.repository.member.MemberRepository; | ||
import com.server.Dotori.global.util.CurrentMemberUtil; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
import org.springframework.security.core.context.SecurityContext; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
import static com.server.Dotori.domain.member.enumType.Role.ROLE_ADMIN; | ||
import static com.server.Dotori.domain.member.enumType.Role.ROLE_MEMBER; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@Transactional | ||
@SpringBootTest | ||
class BoardAlarmServiceTest { | ||
|
||
@Autowired private MemberRepository memberRepository; | ||
@Autowired private PasswordEncoder passwordEncoder; | ||
@Autowired private BoardService boardService; | ||
@Autowired private BoardAlarmService boardAlarmService; | ||
|
||
@BeforeEach | ||
@DisplayName("로그인 되어있는 유저를 세팅하는 테스트") | ||
void currentUser() { | ||
//given | ||
MemberDto memberDto = MemberDto.builder() | ||
.memberName("배태현") | ||
.stuNum("2409") | ||
.password("0809") | ||
.email("[email protected]") | ||
.gender(Gender.MAN) | ||
.build(); | ||
memberRepository.save( | ||
memberDto.toEntity( | ||
passwordEncoder.encode(memberDto.getPassword()) | ||
) | ||
); | ||
System.out.println("======== saved ========="); | ||
|
||
// when login session 발급 | ||
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( | ||
memberDto.getEmail(), | ||
memberDto.getPassword(), | ||
List.of(new SimpleGrantedAuthority(ROLE_ADMIN.name()))); | ||
SecurityContext context = SecurityContextHolder.getContext(); | ||
context.setAuthentication(token); | ||
System.out.println("================================="); | ||
System.out.println(context); | ||
|
||
//then | ||
String currentMemberEmail = CurrentMemberUtil.getCurrentEmail(); | ||
assertEquals("[email protected]", currentMemberEmail); | ||
} | ||
|
||
@Test | ||
@DisplayName("가장 마지막에 등록된 공지사항이 잘 가져와지나요 ?") | ||
public void boardAlarmTest() { | ||
// given // when | ||
boardService.createBoard( | ||
BoardDto.builder() | ||
.title("도토리 공지사항") | ||
.content("도토리 공지사항 생성 테스트") | ||
.build(), null | ||
); | ||
|
||
BoardAlarmDto boardAlarmInfo = boardAlarmService.getBoardAlarmInfo(); | ||
|
||
// then | ||
assertEquals("도토리 공지사항", boardAlarmInfo.getTitle()); | ||
assertEquals(ROLE_MEMBER.name(), boardAlarmInfo.getWriterRole().get(0).name()); | ||
assertEquals(LocalDate.now(), boardAlarmInfo.getLastBoardWriteDate()); | ||
} | ||
} |