11package com .itsu .threedays .controller ;
22
33import com .itsu .threedays .dto .HabitDto ;
4+ import com .itsu .threedays .dto .HabitEditResponseDto ;
45import com .itsu .threedays .dto .HabitResponseDto ;
56import com .itsu .threedays .dto .HabitUpdateRequestDto ;
67import com .itsu .threedays .entity .HabitEntity ;
1819import java .math .BigInteger ;
1920import java .time .LocalDateTime ;
2021import java .util .List ;
22+ import java .util .NoSuchElementException ;
2123import java .util .stream .Collectors ;
2224
2325@ Slf4j
@@ -77,6 +79,29 @@ ResponseEntity<List<HabitResponseDto>> getHabitList(@RequestParam("email") Strin
7779 return ResponseEntity .ok (habitResponseDtos );
7880 }
7981
82+ @ GetMapping ("habits/edit-list" ) //편집시 습관목록조회(중지일 포함)
83+ ResponseEntity <List <HabitEditResponseDto >> getHabitEditList (@ RequestParam ("email" ) String email ) throws Exception {
84+ List <HabitEntity > habits = habitService .findUndeletedAndAllHabits (email );
85+ log .info ("undeletedAndAllHabits: {}" ,habits );
86+ List <HabitEditResponseDto > habitEditListDto = habits .stream ()
87+ .map (habitEntity -> {
88+ HabitEditResponseDto editResponseDto = new HabitEditResponseDto ();
89+ editResponseDto .setId (habitEntity .getId ());
90+ editResponseDto .setTitle (habitEntity .getTitle ());
91+ editResponseDto .setDuration (habitEntity .getDuration ());
92+ editResponseDto .setVisible (habitEntity .isVisible ());
93+ editResponseDto .setComboCount (habitEntity .getComboCount ());
94+ editResponseDto .setAchievementRate (habitEntity .getAchievementRate ());
95+ editResponseDto .setAchievementCount (habitEntity .getAchievementCount ());
96+ editResponseDto .setStopDate (habitEntity .getStopDate ()); //중지일
97+ return editResponseDto ;
98+ })
99+ .collect (Collectors .toList ());
100+ return ResponseEntity .ok (habitEditListDto )
101+ }
102+
103+
104+
80105 @ PutMapping ("habits/{habitId}/edit" ) //습관수정(이름, 기간, 공개여부)
81106 ResponseEntity <HabitResponseDto > updateHabit (@ PathVariable ("habitId" ) Long habitId ,
82107 @ RequestBody HabitUpdateRequestDto habitUpdateDto ) throws Exception {
@@ -90,16 +115,31 @@ ResponseEntity<HabitResponseDto> updateHabit(@PathVariable("habitId") Long habit
90115 ResponseEntity <?> deleteHabit (@ PathVariable ("habitId" ) Long habitId ){
91116 habitService .deleteHabit (habitId );
92117
93- return ResponseEntity .ok ("습관이 성공적으로 삭제되었습니다." );
118+ return ResponseEntity .ok ("Habit deleted successfully." );
119+
120+ }
121+
122+ @ PutMapping ("habits/{habitId}/stop" ) //습관 중지
123+ ResponseEntity <String > stopHabit (@ PathVariable ("habitId" ) Long habitId ){
124+ try {
125+ habitService .stopHabit (habitId );
126+ return ResponseEntity .ok ("Habit stopped successfully." );
127+ } catch (NoSuchElementException e ) {
128+ return ResponseEntity .status (HttpStatus .NOT_FOUND ).body ("Habit not found." );
129+ } catch (IllegalStateException e ) {
130+ return ResponseEntity .status (HttpStatus .BAD_REQUEST ).body (e .getMessage ());
131+ } catch (Exception e ) {
132+ return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR ).body ("An error occurred." );
133+ }
94134
95135 }
96136
97- //습관 그만두기
98137 //습관 편집시 목록
99138
139+
100140 @ GetMapping ("habits/{habitId}/reset" ) //매주마다 달성횟수 리셋
101- ResponseEntity <?> resetAcievement (@ PathVariable ("habitId" ) Long habitId ){
141+ ResponseEntity <String > resetAchievement (@ PathVariable ("habitId" ) Long habitId ){
102142 habitService .resetAchievement (habitId );
103- return ResponseEntity .ok ("달성횟수가 성공적으로 리셋되었습니다 ." );
143+ return ResponseEntity .ok ("Resetting the achievement count was successful ." );
104144 }
105145}
0 commit comments