From 6998aef432c6bfcb7110265b7cf71fca6d73ea24 Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Fri, 28 Jun 2024 22:14:46 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20alarmApi=20=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alarm/controller/AlarmController.java | 24 ++++++++++++++++ .../domain/alarm/controller/api/AlarmApi.java | 27 ++++++++++++++++++ .../domain/alarm/dto/AlarmRequestDTO.java | 14 ++++++++++ .../domain/alarm/dto/AlarmResponseDTO.java | 19 +++++++++++++ .../domain/alarm/service/AlarmService.java | 28 +++++++++++++++++++ .../fiurinee/domain/member/entity/Member.java | 6 ++-- 6 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/example/fiurinee/domain/alarm/controller/AlarmController.java create mode 100644 src/main/java/com/example/fiurinee/domain/alarm/controller/api/AlarmApi.java create mode 100644 src/main/java/com/example/fiurinee/domain/alarm/dto/AlarmRequestDTO.java create mode 100644 src/main/java/com/example/fiurinee/domain/alarm/dto/AlarmResponseDTO.java create mode 100644 src/main/java/com/example/fiurinee/domain/alarm/service/AlarmService.java diff --git a/src/main/java/com/example/fiurinee/domain/alarm/controller/AlarmController.java b/src/main/java/com/example/fiurinee/domain/alarm/controller/AlarmController.java new file mode 100644 index 0000000..64586e9 --- /dev/null +++ b/src/main/java/com/example/fiurinee/domain/alarm/controller/AlarmController.java @@ -0,0 +1,24 @@ +package com.example.fiurinee.domain.alarm.controller; + +import com.example.fiurinee.domain.alarm.controller.api.AlarmApi; +import com.example.fiurinee.domain.alarm.dto.AlarmRequestDTO; +import com.example.fiurinee.domain.alarm.dto.AlarmResponseDTO; +import com.example.fiurinee.domain.alarm.service.AlarmService; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class AlarmController implements AlarmApi { + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @Override + public ResponseEntity updateAlarmStatus(Long id, AlarmRequestDTO alarmRequestDTO) { + AlarmResponseDTO responseDTO = alarmService.updateAlarmStatus(id, alarmRequestDTO.isAlarm()); + return ResponseEntity.ok(responseDTO); + } + +} diff --git a/src/main/java/com/example/fiurinee/domain/alarm/controller/api/AlarmApi.java b/src/main/java/com/example/fiurinee/domain/alarm/controller/api/AlarmApi.java new file mode 100644 index 0000000..bc9e619 --- /dev/null +++ b/src/main/java/com/example/fiurinee/domain/alarm/controller/api/AlarmApi.java @@ -0,0 +1,27 @@ +package com.example.fiurinee.domain.alarm.controller.api; + +import com.example.fiurinee.domain.alarm.dto.AlarmRequestDTO; +import com.example.fiurinee.domain.alarm.dto.AlarmResponseDTO; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; + +@Tag(name = "Alarm", description = "알람 관련 API") +@RequestMapping("/member") +public interface AlarmApi { + @Operation( + summary = "알람 상태 업데이트", + description = "회원의 알람 상태를 업데이트합니다.", + security = @SecurityRequirement(name = "bearerAuth") + ) + @ApiResponse(responseCode = "200", description = "알람 상태 업데이트 성공") + @ApiResponse(responseCode = "401", description = "인증 실패") + @PutMapping("/{id}/alarm") + ResponseEntity updateAlarmStatus(@PathVariable Long id, @RequestBody AlarmRequestDTO alarmRequestDTO); +} diff --git a/src/main/java/com/example/fiurinee/domain/alarm/dto/AlarmRequestDTO.java b/src/main/java/com/example/fiurinee/domain/alarm/dto/AlarmRequestDTO.java new file mode 100644 index 0000000..0b844b7 --- /dev/null +++ b/src/main/java/com/example/fiurinee/domain/alarm/dto/AlarmRequestDTO.java @@ -0,0 +1,14 @@ +package com.example.fiurinee.domain.alarm.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class AlarmRequestDTO { + private boolean alarm; +} diff --git a/src/main/java/com/example/fiurinee/domain/alarm/dto/AlarmResponseDTO.java b/src/main/java/com/example/fiurinee/domain/alarm/dto/AlarmResponseDTO.java new file mode 100644 index 0000000..0b1c0f7 --- /dev/null +++ b/src/main/java/com/example/fiurinee/domain/alarm/dto/AlarmResponseDTO.java @@ -0,0 +1,19 @@ +package com.example.fiurinee.domain.alarm.dto; + +import com.example.fiurinee.domain.member.entity.Member; +import lombok.*; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class AlarmResponseDTO { + private boolean alarm; + + public static AlarmResponseDTO of(Member member) { + return AlarmResponseDTO.builder() + .alarm(member.isAlarm()) + .build(); + } +} diff --git a/src/main/java/com/example/fiurinee/domain/alarm/service/AlarmService.java b/src/main/java/com/example/fiurinee/domain/alarm/service/AlarmService.java new file mode 100644 index 0000000..b1be0c5 --- /dev/null +++ b/src/main/java/com/example/fiurinee/domain/alarm/service/AlarmService.java @@ -0,0 +1,28 @@ +package com.example.fiurinee.domain.alarm.service; + +import com.example.fiurinee.domain.alarm.dto.AlarmResponseDTO; +import com.example.fiurinee.domain.member.entity.Member; +import com.example.fiurinee.domain.member.repository.MemberRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class AlarmService { + + private final MemberRepository memberRepository; + + public AlarmService(MemberRepository memberRepository) { + this.memberRepository = memberRepository; + } + + + @Transactional + public AlarmResponseDTO updateAlarmStatus(Long memberId, boolean alarm) { + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new IllegalArgumentException("Member not found with id: " + memberId)); + member.setAlarm(alarm); + memberRepository.save(member); + return AlarmResponseDTO.of(member); + } +} diff --git a/src/main/java/com/example/fiurinee/domain/member/entity/Member.java b/src/main/java/com/example/fiurinee/domain/member/entity/Member.java index 4673bf5..eba38c6 100644 --- a/src/main/java/com/example/fiurinee/domain/member/entity/Member.java +++ b/src/main/java/com/example/fiurinee/domain/member/entity/Member.java @@ -7,15 +7,13 @@ import com.example.fiurinee.domain.recommendFlower.entity.RecommendFlower; import com.fasterxml.jackson.annotation.JsonManagedReference; import jakarta.persistence.*; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import java.net.URL; import java.util.List; @Getter +@Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name = "member")