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

feat: alarmApi 개발 #37

Merged
merged 1 commit into from
Jun 28, 2024
Merged
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,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<AlarmResponseDTO> updateAlarmStatus(Long id, AlarmRequestDTO alarmRequestDTO) {
AlarmResponseDTO responseDTO = alarmService.updateAlarmStatus(id, alarmRequestDTO.isAlarm());
return ResponseEntity.ok(responseDTO);
}

}
Original file line number Diff line number Diff line change
@@ -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<AlarmResponseDTO> updateAlarmStatus(@PathVariable Long id, @RequestBody AlarmRequestDTO alarmRequestDTO);
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading