-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from Tave-13th-Project-Team-4-Fiurinee/feature…
…/alarm feat: alarmApi 개발
- Loading branch information
Showing
6 changed files
with
114 additions
and
4 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/main/java/com/example/fiurinee/domain/alarm/controller/AlarmController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/example/fiurinee/domain/alarm/controller/api/AlarmApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/example/fiurinee/domain/alarm/dto/AlarmRequestDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/example/fiurinee/domain/alarm/dto/AlarmResponseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/example/fiurinee/domain/alarm/service/AlarmService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters