Skip to content

Commit

Permalink
Merge pull request #37 from Tave-13th-Project-Team-4-Fiurinee/feature…
Browse files Browse the repository at this point in the history
…/alarm

feat: alarmApi 개발
  • Loading branch information
qormoon authored Jun 28, 2024
2 parents 49bca7a + 6998aef commit bdf8b5c
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 4 deletions.
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

0 comments on commit bdf8b5c

Please sign in to comment.