Skip to content

Commit

Permalink
Merge pull request #11 from HealthMer/refactor/#10-Timer_Apply_Token
Browse files Browse the repository at this point in the history
refactor: timer create userid=1 고정이슈 complete
  • Loading branch information
Dylan-yoon authored Nov 26, 2024
2 parents 69312e1 + 3238deb commit 514f978
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
Expand All @@ -23,7 +22,6 @@
import com.minijean.healthmer.model.dto.TimerRequest;
import com.minijean.healthmer.model.service.TimerService;
import com.minijean.healthmer.util.JwtUtil;
import com.minijean.healthmer.model.dto.SearchCondition;

@RestController
@RequestMapping("/api/v1/timer")
Expand All @@ -35,7 +33,6 @@ public class TimerController {
public TimerController(TimerService timerService, JwtUtil jtwUtil) {
this.timerService = timerService;
this.jtwUtil = jtwUtil;

}

@GetMapping("")
Expand All @@ -48,17 +45,7 @@ public ResponseEntity<?> listAll(@RequestHeader(HttpHeaders.AUTHORIZATION) Strin
return new ResponseEntity<>(list, HttpStatus.OK);
}

@GetMapping("/search")
public ResponseEntity<?> search(@ModelAttribute SearchCondition condition) {
System.out.println("안 된다");
System.out.println(condition.toString());
List<Timer> list = timerService.searchTimer(condition);

if (list == null || list.size() == 0) {
return new ResponseEntity<Void>(HttpStatus.NO_CONTENT);
}
return new ResponseEntity<>(list, HttpStatus.OK);
}

@GetMapping("/{id}")
public ResponseEntity<?> oneTimer(@PathVariable("id") long id) {
Expand Down Expand Up @@ -122,11 +109,14 @@ public ResponseEntity<?> listCategory(@PathVariable("id") long id) {
}

@PostMapping("/create")
public ResponseEntity<Timer> create(@RequestBody TimerRequest timerRequest) {

public ResponseEntity<Timer> create(@RequestHeader(HttpHeaders.AUTHORIZATION) String authorizationHeader, @RequestBody TimerRequest timerRequest) {
long userId = jtwUtil.extractUserId(authorizationHeader);
Timer timer = timerRequest.getTimer();
timer.setUserId(userId);
timerRequest.setTimer(timer);

Timer createdTimer = timerService.createTimer(timerRequest);

return new ResponseEntity<>(createdTimer, HttpStatus.CREATED);
}

}
7 changes: 2 additions & 5 deletions HealthMer/src/main/resources/Mappers/TimerMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
</select>

<select id="selectOne" resultType="Timer" parameterType="long">
SELECT
t.id, t.user_id, t.title, t.views_count, t.complete_count, t.level,
t.created_at, SUM(r.time) AS total_routine_time
SELECT t.id, t.user_id, t.title, t.views_count, t.complete_count, t.level, t.created_at, SUM(r.time) AS total_routine_time
FROM timer_info t
JOIN
routine_info r ON r.timer_info_id = t.id
WHERE t.id = #{id}
GROUP BY
t.id;
GROUP BY t.id;
</select>

<select id="selectHealthCategory" resultType="HealthCategory">
Expand Down

0 comments on commit 514f978

Please sign in to comment.