Skip to content

Schedule revenue #6

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 2 commits 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
80 changes: 76 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,92 @@
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.model.Revenue;
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);

}

@DeleteMapping("/personalinfo/{id}")
private void deletePersonalInfo(@PathVariable("id") int id) {
demoService.delete(id);
}


@PostMapping("/revenue")
private int saveRevenue(@RequestBody Revenue revenue) {
demoService.saveOrUpdate(revenue);
return revenue.getId();
}

@GetMapping("/revenue/{id}")
private Revenue getRevenue(@PathVariable("id") int id) {
return demoService.getRevenueById(id);

}

@DeleteMapping("/revenue/{id}")
private void deleteRevenue(@PathVariable("id") int id) {
demoService.deleteRevenue(id);
}


@PostMapping("/schedule")
private int saveSchedule(@RequestBody Revenue schedule) {
demoService.saveOrUpdate(schedule);
return schedule.getId();
}

@GetMapping("/schedule/{id}")
private Revenue getSchedule(@PathVariable("id") int id) {
return demoService.getRevenueById(id);

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

@DeleteMapping("/schedule/{id}")
private void deleteSchedule(@PathVariable("id") int id) {
demoService.deleteSchedule(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;
}

}
55 changes: 55 additions & 0 deletions src/main/java/com/codejam/demo/model/Revenue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

package com.codejam.demo.model;

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

@Entity
@Table(name = "revenue")
public class Revenue {

@Id
@Column(name = "id")
private int id;
@Column(name = "monthly_rate", length = 50)
private String monthlyRate;
@Column(name = "event_name", length = 60)
private String eventName;
@Column(name = "date_time", length = 50)
private String dateTime;

public int getId() {
return id;
}

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

public String getMonthlyRate() {
return monthlyRate;
}

public void setMonthlyRate(String monthlyRate) {
this.monthlyRate = monthlyRate;
}

public String getEventName() {
return eventName;
}

public void setEventName(String eventName) {
this.eventName = eventName;
}

public String getDateTime() {
return dateTime;
}

public void setDateTime(String dateTime) {
this.dateTime = dateTime;
}

}
55 changes: 55 additions & 0 deletions src/main/java/com/codejam/demo/model/Schedule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

package com.codejam.demo.model;

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

@Entity
@Table(name = "schedule")
public class Schedule {

@Id
@Column(name = "id")
private int id;
@Column(name = "venue", length = 50)
private String venue;
@Column(name = "event_name", length = 60)
private String eventName;
@Column(name = "date_time", length = 50)
private String dateTime;

public int getId() {
return id;
}

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

public String getVenue() {
return venue;
}

public void setVenue(String venue) {
this.venue = venue;
}

public String getEventName() {
return eventName;
}

public void setEventName(String eventName) {
this.eventName = eventName;
}

public String getDateTime() {
return dateTime;
}

public void setDateTime(String dateTime) {
this.dateTime = dateTime;
}

}
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> {
}
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.Revenue;

public interface RevenueRepository extends CrudRepository<Revenue, Integer> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.codejam.demo.repository;

import org.springframework.data.repository.CrudRepository;

import com.codejam.demo.model.Schedule;


public interface ScheduleRepository extends CrudRepository<Schedule, Integer> {
}
84 changes: 84 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,84 @@
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;
import com.codejam.demo.model.Revenue;
import com.codejam.demo.model.Schedule;
import com.codejam.demo.repository.RevenueRepository;
import com.codejam.demo.repository.ScheduleRepository;

@Service
public class DemoService {

@Autowired
PersonalInfoRepository personalInfoRepository;

@Autowired
RevenueRepository revenueRepository;

@Autowired
ScheduleRepository scheduleRepository;

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);
}




public List<Schedule> getSchedule() {
List<Schedule> schedules = new ArrayList<Schedule>();
scheduleRepository.findAll().forEach(schedule ->schedules.add(schedule));
return schedules;
}

public void saveOrUpdate(Schedule schedule) {
scheduleRepository.save(schedule);
}

public Schedule getScheduleById(int id) {
return scheduleRepository.findById(id).get();
}

public void deleteSchedule(int id) {
scheduleRepository.deleteById(id);
}



public List<Revenue> getRevenue() {
List<Revenue> revenues = new ArrayList<Revenue>();
revenueRepository.findAll().forEach(revenue ->revenues.add(revenue));
return revenues;
}

public void saveOrUpdate(Revenue revenue) {
revenueRepository.save(revenue);
}

public Revenue getRevenueById(int id) {
return revenueRepository.findById(id).get();
}

public void deleteRevenue(int id) {
revenueRepository.deleteById(id);
}
}