Skip to content

add idol personal info #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions src/main/java/com/codejam/demo/controller/DemoController.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,55 @@
package com.codejam.demo.controller;

import lombok.RequiredArgsConstructor;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
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.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.codejam.demo.model.PersonalInfo;
import com.codejam.demo.service.DemoService;

@RestController
@RequiredArgsConstructor
@RequestMapping(path = "demo")
public class DemoController {

@Autowired
DemoService demoService;

@GetMapping(path = "/unit-test")
ResponseEntity<Integer> getUnitTestResult() throws Exception {
return null;
}

@GetMapping("/personalinfo/all")
private List<PersonalInfo> getAllPersonalInfo() {
return demoService.getAllPersonalInfo();

}

@PostMapping("/personalinfo")
private int savePersonalInfo(@RequestBody PersonalInfo personalInfo) {
demoService.saveOrUpdate(personalInfo);
return personalInfo.getId();
}

@GetMapping("/personalinfo/{id}")
private PersonalInfo getPersonalInfo(@PathVariable("id") int id) {
return demoService.getPersonalInfoById(id);

@GetMapping(path = "/unit-test")
ResponseEntity<Integer> getUnitTestResult() throws Exception{
return null;
}
}

@DeleteMapping("/personalinfo/{id}")
private void deletePersonalInfo(@PathVariable("id") int id) {
demoService.delete(id);
}
}
65 changes: 65 additions & 0 deletions src/main/java/com/codejam/demo/model/PersonalInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

package com.codejam.demo.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "personal_information")
public class PersonalInfo {

@Id
@Column(name = "id")
private int id;
@Column(name = "real_name", length = 50)
private String realName;
@Column(name = "idol_name", length = 60)
private String idolName;
@Column(name = "address", length = 255)
private String idolAddress;
@Column(name = "idol_status", length = 25)
private String idolStatus;

public int getId() {
return id;
}

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

public String getRealName() {
return realName;
}

public void setRealName(String realName) {
this.realName = realName;
}

public String getIdolName() {
return idolName;
}

public void setIdolName(String idolName) {
this.idolName = idolName;
}

public String getIdolAddress() {
return idolAddress;
}

public void setIdolAddress(String idolAddress) {
this.idolAddress = idolAddress;
}

public String getIdolStatus() {
return idolStatus;
}

public void setIdoltaStus(String idolStatus) {
this.idolStatus = idolStatus;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.codejam.demo.repository;

import org.springframework.data.repository.CrudRepository;

import com.codejam.demo.model.PersonalInfo;

public interface PersonalInfoRepository extends CrudRepository<PersonalInfo, Integer> {
}
33 changes: 33 additions & 0 deletions src/main/java/com/codejam/demo/service/DemoService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.codejam.demo.service;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.codejam.demo.model.PersonalInfo;
import com.codejam.demo.repository.PersonalInfoRepository;

@Service
public class DemoService {

@Autowired
PersonalInfoRepository personalInfoRepository;

public List<PersonalInfo> getAllPersonalInfo() {
List<PersonalInfo> personalInfos = new ArrayList<PersonalInfo>();
personalInfoRepository.findAll().forEach(personalInfo -> personalInfos.add(personalInfo));
return personalInfos;
}

public PersonalInfo getPersonalInfoById(int id) {
return personalInfoRepository.findById(id).get();
}

public void saveOrUpdate(PersonalInfo personalInfo) {
personalInfoRepository.save(personalInfo);
}

public void delete(int id) {
personalInfoRepository.deleteById(id);
}
}