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

공지사항과 이벤트 목록을 조회한다. #39

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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,28 @@
package com.example.parking.api.announcement;

import com.example.parking.domain.announcement.Announcement;
import com.example.parking.domain.announcement.AnnouncementRepository;
import com.example.parking.domain.announcement.AnnouncementType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AnnouncementController {

private final AnnouncementRepository announcementRepository;

public AnnouncementController(AnnouncementRepository announcementRepository) {
this.announcementRepository = announcementRepository;
}

@GetMapping("/announcements")
public ResponseEntity<Page<Announcement>> findAnnouncements(@RequestParam String type, Pageable pageable) {
AnnouncementType announcementType = AnnouncementType.findType(type);
Page<Announcement> announcements = announcementRepository.findAllByAnnouncementType(announcementType, pageable);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 응답이 나가면 정적파일이 아니라 파일의 filename 이 담긴 json 이 나가게 되는거 아닌가요?? html 파일이 나가나요??

return ResponseEntity.ok(announcements);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ private void validatePassword(Member member, String password) {
public void deleteMember(Long memberId) {
Member member = memberRepository.getById(memberId);
member.delete();
}

@Transactional(readOnly = true)
public MemberInfoResponse findMemberInfo(Long memberId) {
Member member = memberRepository.getById(memberId);

return new MemberInfoResponse(member.getName(), member.getEmail());
}

@Transactional
public void changePassword(Long memberId, PasswordChangeRequest dto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ public void saveAll(List<Parking> parkingLots) {
public Set<Parking> getParkingLots(Set<String> parkingNames) {
return parkingRepository.findAllByBaseInformationNameIn(parkingNames);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.example.parking.domain.announcement;

import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Getter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Announcement {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String title;
private String fileName;
private LocalDateTime createdAt;

@Enumerated(EnumType.STRING)
private AnnouncementType announcementType;

public Announcement(String title, String fileName, LocalDateTime createdAt, AnnouncementType announcementType) {
this.title = title;
this.fileName = fileName;
this.createdAt = createdAt;
this.announcementType = announcementType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.parking.domain.announcement;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

public interface AnnouncementRepository extends JpaRepository<Announcement, Long> {

Page<Announcement> findAllByAnnouncementType(AnnouncementType announcementType, Pageable pageable);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Page 로 하신 이유가 있나요?? 제가 Page 를 잘몰라서..

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.parking.domain.announcement;

import com.example.parking.application.member.dto.MemberNotFoundException;

import java.util.Arrays;

public enum AnnouncementType {

NOTICE("notice"),
EVENT("event");

private final String type;

AnnouncementType(String type) {
this.type = type;
}

public static AnnouncementType findType(String type) {
return Arrays.stream(AnnouncementType.values())
.filter(announcementType -> announcementType.getType().equals(type))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("찾을 수 없는 타입"));
}

public String getType() {
return type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public boolean checkPassword(String password) {

public void delete() {
deleted = Boolean.TRUE;
}

public void changePassword(String previousPassword, String newPassword) {
if (checkPassword(previousPassword)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public void addInterceptors(InterceptorRegistry registry) {
.addPathPatterns("/**")
.excludePathPatterns(List.of(
"/users",
"/login"
"/login",
"/announcements/**"
));
}

Expand Down
Loading