Skip to content

Commit

Permalink
Merge pull request #2 from HealthMer/Feat/#1-TimerCRUD
Browse files Browse the repository at this point in the history
feat: 타이머 등록 조회 삭제 기능 추가 (삭제 기능 점검 미흡)
  • Loading branch information
eosa1414 authored Nov 21, 2024
2 parents de08554 + 1ed3778 commit 710c2fb
Show file tree
Hide file tree
Showing 12 changed files with 712 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.springframework.context.annotation.Configuration;

@Configuration
@MapperScan(basePackages = "com.minijean.healthmer.model")
@MapperScan(basePackages = "com.minijean.healthmer.model.dao")
public class DBConfig {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.minijean.healthmer.controller;

import java.util.List;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.minijean.healthmer.model.dto.HealthCategory;
import com.minijean.healthmer.model.dto.Routine;
import com.minijean.healthmer.model.dto.Timer;
import com.minijean.healthmer.model.dto.TimerCategory;
import com.minijean.healthmer.model.dto.TimerRequest;
import com.minijean.healthmer.model.service.TimerService;

@RestController
@RequestMapping("/api/v1/timer")
@CrossOrigin("http://localhost:5173")
public class TimerController {

private final TimerService timerService;

public TimerController(TimerService timerService) {
this.timerService = timerService;
}

@GetMapping("")
public ResponseEntity<?> listAll(){
List<Timer> list = timerService.getTimerList();

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

@DeleteMapping("/{id}")
public ResponseEntity<?> deleteTimer(@PathVariable("id") long id){

System.out.println("id는" + id);
boolean isDeleted = timerService.removeTimer(id);

if(isDeleted) {
return ResponseEntity.status(HttpStatus.OK).body("Timer deleted");
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Fail Delete");
}

@GetMapping("/{id}/routine")
public ResponseEntity<?> listRoutine(@PathVariable("id") long id){
List<Routine> list = timerService.getRoutineList(id);

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

@GetMapping("/category")
public ResponseEntity<?> listCategory(){
List<HealthCategory> list = timerService.getHealthCategoryList();

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

@GetMapping("/{id}/category")
public ResponseEntity<?> listCategory(@PathVariable("id") long id){
List<TimerCategory> list = timerService.getCategoryList(id);

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

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

Timer createdTimer = timerService.createTimer(timerRequest);

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

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.minijean.healthmer.model.dao;

import java.util.List;

import com.minijean.healthmer.model.dto.HealthCategory;
import com.minijean.healthmer.model.dto.Routine;
import com.minijean.healthmer.model.dto.SearchCondition;
import com.minijean.healthmer.model.dto.Timer;
import com.minijean.healthmer.model.dto.TimerCategory;

public interface TimerDao {

/** 전체 타이머 조회 */
public List<Timer> selectAll();

/** 전체 헬스 카테고리 조회 */
public List<HealthCategory> selectHealthCategory();

/** 타이머 하나의 전체 카테고리 조회 */
public List<TimerCategory> selectAllCategory(long id);

/** 타이머 하나의 전체 루틴 조회 */
public List<Routine> selectAllRoutine(long id);

/** 타이머 등록 */
public int insertTimer(Timer timer);

/** 타이머 카테고리 등록 */
public int insertTimerCategory(List<TimerCategory> category);

/** 타이머 하위 루틴 등록 */
public int insertRoutines(List<Routine> routines);

/** 타이머 수정 */
public int updateTimer(Timer timer);

/** 타이머 하위 루틴 수정 */
public int updateRoutines(List<Routine> routines);

/** 타이머 한 개 삭제 (하위 루틴도 삭제됨) */
public int deleteTimer(long id);

/** 타이머 달성치 증가 */
public void updateCompleteCount(long id);

/** 검색을 통한 타이머 조회*/
public List<Timer> searchTimer(SearchCondition condition);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.minijean.healthmer.model.dto;

public class HealthCategory {
private long id;
private String name;

public HealthCategory() {

}

public HealthCategory(long id, String name) {
super();
this.id = id;
this.name = name;
}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return "HealthCategory [id=" + id + ", name=" + name + "]";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.minijean.healthmer.model.dto;

public class Routine {
private long id;
private long timerInfoId;
private String name;
private short time;
private short isRest;

public Routine() {

}

public Routine(long id, long timerInfoId, String name, short time, short isRest) {
super();
this.id = id;
this.timerInfoId = timerInfoId;
this.name = name;
this.time = time;
this.isRest = isRest;
}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public long getTimerInfoId() {
return timerInfoId;
}

public void setTimerInfoId(long timerInfoId) {
this.timerInfoId = timerInfoId;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public short getTime() {
return time;
}

public void setTime(short time) {
this.time = time;
}

public short getIsRest() {
return isRest;
}

public void setIsRest(short isRest) {
this.isRest = isRest;
}

@Override
public String toString() {
return "Routine [id=" + id + ", timerInfoId=" + timerInfoId + ", name=" + name + ", time=" + time + ", isRest="
+ isRest + "]";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.minijean.healthmer.model.dto;

public class SearchCondition {
private String key;
private String word;
private String orderBy;
private String orderByDir;

public SearchCondition() {

}

public SearchCondition(String key, String word, String orderBy, String orderByDir) {
super();
this.key = key;
this.word = word;
this.orderBy = orderBy;
this.orderByDir = orderByDir;
}

public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}

public String getWord() {
return word;
}

public void setWord(String word) {
this.word = word;
}

public String getOrderBy() {
return orderBy;
}

public void setOrderBy(String orderBy) {
this.orderBy = orderBy;
}

public String getOrderByDir() {
return orderByDir;
}

public void setOrderByDir(String orderByDir) {
this.orderByDir = orderByDir;
}

@Override
public String toString() {
return "SearchCondition [key=" + key + ", word=" + word + ", orderBy=" + orderBy + ", orderByDir=" + orderByDir
+ "]";
}

}
Loading

0 comments on commit 710c2fb

Please sign in to comment.