Skip to content

Commit

Permalink
Merge pull request #62 from Clubber2024/feat/#53-notice-api-구현
Browse files Browse the repository at this point in the history
feat : notice api 구현
  • Loading branch information
sseongeun authored May 12, 2024
2 parents c6132cb + 5794f77 commit de82909
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ dependencies {

//devtools
compileOnly("org.springframework.boot:spring-boot-devtools")

}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.clubber.ClubberServer.domain.club.dto.*;
import com.clubber.ClubberServer.domain.club.exception.ClubNotFoundException;
import com.clubber.ClubberServer.domain.club.repository.ClubRepository;
import com.clubber.ClubberServer.domain.notice.dto.NoticesDto;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;
Expand Down Expand Up @@ -124,4 +126,6 @@ public OneClubDto getClubByName(String clubName) {
.map(this::convertToClubDto)
.orElseThrow(() -> new ClubNotFoundException(clubName+"이름을 가지는 동아리 및 소모임이 없습니다."));
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.clubber.ClubberServer.domain.notice.controller;

import com.clubber.ClubberServer.domain.notice.domain.Notice;
import com.clubber.ClubberServer.domain.notice.dto.NoticesDto;
import com.clubber.ClubberServer.domain.notice.repository.NoticeRepository;
import com.clubber.ClubberServer.domain.notice.service.NoticeService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class NoticeController {
private final NoticeService noticeService;
private final NoticeRepository noticeRepository;


@GetMapping("/v1/notice")
public ResponseEntity<List<NoticesDto>> getNotices(){
List<NoticesDto> notices=noticeService.getSortedNotices();
return ResponseEntity.ok(notices);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.clubber.ClubberServer.domain.notice.dto;

import com.clubber.ClubberServer.domain.club.dto.SimpleCenterDto;
import lombok.Builder;
import lombok.Data;

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

@Data
public class NoticesDto {
private Long noticeId;
private String content;
private LocalDateTime createdAt;


@Builder
public NoticesDto(Long noticeId, String content,LocalDateTime createdAt){
this.noticeId=noticeId;
this.content=content;
this.createdAt=createdAt;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.clubber.ClubberServer.domain.notice.dto;

import lombok.Builder;
import lombok.Data;

import java.time.LocalDateTime;

@Data
public class OneNoticeDto {
private Long id;
private String content;
private LocalDateTime createdAt;


@Builder
public OneNoticeDto(Long id, String content,LocalDateTime createdAt){
this.id=id;
this.content=content;
this.createdAt=createdAt;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.clubber.ClubberServer.domain.notice.repository;

import com.clubber.ClubberServer.domain.notice.domain.Notice;
import com.clubber.ClubberServer.domain.notice.dto.NoticesDto;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface NoticeRepository extends JpaRepository<Notice,Long> {
List<Notice> findAll(Sort sort);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.clubber.ClubberServer.domain.notice.service;

import com.clubber.ClubberServer.domain.club.dto.DivisionCenterDto;
import com.clubber.ClubberServer.domain.club.dto.SimpleCenterDto;
import com.clubber.ClubberServer.domain.common.BaseEntity;
import com.clubber.ClubberServer.domain.notice.domain.Notice;
import com.clubber.ClubberServer.domain.notice.dto.NoticesDto;
import com.clubber.ClubberServer.domain.notice.repository.NoticeRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

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

@Service
@RequiredArgsConstructor
public class NoticeService {

private final NoticeRepository noticeRepository;
public List<NoticesDto> getSortedNotices(){
Sort sort =Sort.by(Sort.Direction.DESC,"createdAt");
List <Notice> notices=noticeRepository.findAll(sort);
List <NoticesDto> noticeDto = notices.stream()
.map(notice -> new NoticesDto(notice.getId(), notice.getContent(), notice.getCreatedAt()))
.collect(Collectors.toList());
return noticeDto;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
//.requestMatchers(PathRequest.toH2Console()).permitAll()
.requestMatchers("/v1/clubs/**").permitAll()
.requestMatchers("/v1/search/**").permitAll()
.requestMatchers("/v1/notice").permitAll()
.anyRequest().hasRole("USER"));
return http.build();
}
Expand Down

0 comments on commit de82909

Please sign in to comment.