Changeset 6729ba5


Ignore:
Timestamp:
01/15/21 16:39:45 (4 years ago)
Author:
Vzdra <vladko.zdravkovski@…>
Branches:
master
Children:
81c9e25
Parents:
ed3f5c4
Message:

finished work edit

Files:
6 added
7 edited

Legend:

Unmodified
Added
Removed
  • client_app/src/components/item_components/internship_component.js

    red3f5c4 r6729ba5  
    11import React from 'react';
    22import {Header, List, Segment, Button} from 'semantic-ui-react';
     3import {Link} from "react-router-dom";
    34
    45const Internships = (props) => {
     
    67        <Segment>
    78            <Header as="h3">{props.item.title}</Header>
    8             {props.item.type!=="USER" ? <Button primary>Edit</Button> : <span> </span>}
     9            {props.item.type!=="USER" ? <Button primary as={Link} to={{
     10                pathname: "/edit/internship",
     11                state: {
     12                    index: props.index,
     13                    item: props.item
     14                }
     15            }}>Edit</Button> : <span> </span>}
    916            <Segment>{props.item.description}</Segment>
    1017            <Segment>
  • client_app/src/components/item_components/job_component.js

    red3f5c4 r6729ba5  
    77        <Segment>
    88            <Header as="h3">{props.item.title}</Header>
    9             {props.item.type!=="USER" ? <Button primary as={Link} to={{
     9            {props.item.accountType!=="USER" ? <Button primary as={Link} to={{
    1010                pathname: "/edit/job",
    1111                state: {
    12                     jobId: props.item.id,
    13                     accId: props.item.accId,
    14                     type: props.item.type
     12                    index: props.index,
     13                    item: props.item
    1514                }
    1615            }}>Edit</Button> : <span> </span>}
  • client_app/src/components/item_components/project_component.js

    red3f5c4 r6729ba5  
    11import React from 'react';
    22import {Header, List, Segment, Button} from 'semantic-ui-react';
     3import {Link} from "react-router-dom";
    34
    45const Projects = (props) => {
     
    78        <Segment>
    89            <Header as="h3">{props.item.title}</Header>
    9             {props.item.type!=="USER" ? <Button primary>Edit</Button> : <span> </span>}
     10            {props.item.type!=="USER" ? <Button primary as={Link} to={{
     11                pathname: "/edit/project",
     12                state: {
     13                    index: props.index,
     14                    item: props.item
     15                }
     16            }}>Edit</Button> : <span> </span>}
    1017            <Segment>{props.item.description}</Segment>
    1118            <Segment>
  • client_app/src/components/main/App.js

    red3f5c4 r6729ba5  
    2424import InternshipRegister from "../work_register/internship_register";
    2525import ProjectRegister from "../work_register/project_register";
    26 import EditJob from "../work_edit/test";
     26import EditJob from "../work_edit/edit_job";
     27import EditInternship from "../work_edit/edit_internship";
     28import EditProject from "../work_edit/edit_project";
    2729
    2830class App extends Component{
     
    6365                      <Route path={"/register/project"} render={() => <ProjectRegister accountId={this.state.currentUser.id} type={this.state.currentUser.type} updateProjects={this.updateProjects} />}/>
    6466                      <Route path={"/edit/job"} render={(props) => <EditJob {...props}  editJob={this.editJob}/>} />
    65                       {/*<Route path={"/edit/internship"} render={(props) => <EditInternship {...props}  editJob={this.editInternship}/>} />*/}
    66                       {/*<Route path={"/edit/project"} render={(props) => <EditProject {...props}  editJob={this.editProject}/>} />*/}
     67                      <Route path={"/edit/internship"} render={(props) => <EditInternship {...props}  editInternship={this.editInternship}/>} />
     68                      <Route path={"/edit/project"} render={(props) => <EditProject {...props}  editProject={this.editProject}/>} />
    6769                      <Route path={"/logout"} render={() => <Redirect to={"/login"}/>}/>
    6870                      <Route path={"/"} render={() => <Redirect to={"/login"}/>}/>
     
    121123
    122124    editJob = (job, index) => {
     125      let jobs = this.state.currentUser.jobs;
     126      jobs[index] = job;
     127
    123128      this.setState(prevState => ({
    124129          currentUser:{
    125130              ...prevState.currentUser,
    126               jobs: Object.assign([],this.state.jobs,{[index]: job})
     131              jobs: jobs
    127132          }
    128133      }))
     
    130135
    131136    editInternship = (internship, index) => {
     137        let interns = this.state.currentUser.internships;
     138        interns[index] = internship;
     139
    132140        this.setState(prevState => ({
    133141            currentUser:{
    134142                ...prevState.currentUser,
    135                 internships: Object.assign([],this.state.jobs,{[index]: internship})
     143                internships: interns
    136144            }
    137145        }))
     
    139147
    140148    editProject = (project, index) => {
     149        let proj = this.state.currentUser.projects;
     150        proj[index] = project;
     151
    141152        this.setState(prevState => ({
    142153            currentUser:{
    143154                ...prevState.currentUser,
    144                 projects: Object.assign([],this.state.jobs,{[index]: project})
     155                projects: proj
    145156            }
    146157        }))
  • src/main/java/it/finki/tinki/model/dto/response/work/WorkResponseDTO.java

    red3f5c4 r6729ba5  
    1313    String accountEmail;
    1414    String accountName;
     15    Long accountId;
    1516    AccountType accountType;
    1617    String error;
     
    2829        this.description = description;
    2930        this.salary = salary;
     31        this.accountId = account.getId();
    3032        this.accountEmail = account.getEmail();
    3133        this.accountName = account.getName();
  • src/main/java/it/finki/tinki/service/impl/WorkServiceImpl.java

    red3f5c4 r6729ba5  
    131131        j.setDescription(description);
    132132        j.setSalary(salary);
     133        j.setOpenSpots(openSpots);
    133134
    134135        return this.internshipRepository.save(j);
  • src/main/java/it/finki/tinki/web/controller/WorkEditController.java

    red3f5c4 r6729ba5  
    44import it.finki.tinki.model.Work.Job;
    55import it.finki.tinki.model.Work.Project;
     6import it.finki.tinki.model.dto.edit.work.InternshipEditDTO;
     7import it.finki.tinki.model.dto.edit.work.WorkEditDTO;
    68import it.finki.tinki.model.dto.register.work.InternshipRegisterDTO;
    79import it.finki.tinki.model.dto.register.work.JobRegisterDTO;
     
    2931
    3032    @PostMapping("/job/{id}")
    31     public Map<String, String> editJob(@PathVariable Long id,
    32                                        @RequestBody JobRegisterDTO body){
     33    public JobResponseDTO editJob(@PathVariable Long id,
     34                                  @RequestBody WorkEditDTO body){
    3335
    34         Map<String, String> response = new HashMap<>();
     36        Job j = this.workService.getJobById(id);
    3537
    36         if(body.getAccountId().equals(this.workService.getJobById(id).getAccount().getId())) {
     38        if(body.getAccountId().equals(j.getAccount().getId())) {
    3739            Job k = this.workService.editJob(id, body.getTitle(), body.getDescription(), body.getSalary());
    3840            if(k!=null){
    39                 response.put("success", "Job edited successfully!");
    40                 return response;
     41                return new JobResponseDTO(k);
    4142            }
    4243        }
    4344
    44         response.put("error", "Internship edit failed!");
    45         return response;
     45        return new JobResponseDTO();
    4646    }
    4747
    4848    @PostMapping("/internship/{id}")
    49     public Map<String, String> editInternship(@PathVariable Long id,
    50                                                 @RequestBody InternshipRegisterDTO body){
     49    public InternshipResponseDTO editInternship(@PathVariable Long id,
     50                                                @RequestBody InternshipEditDTO body){
    5151
    52         Map<String, String> response = new HashMap<>();
     52        Internship i = this.workService.getInternshipById(id);
    5353
    54         if(body.getAccountId().equals(this.workService.getInternshipById(id).getAccount().getId())){
     54        if(body.getAccountId().equals(i.getAccount().getId())){
    5555            Internship k = this.workService.editInternship(id, body.getTitle(), body.getDescription(), body.getSalary(), body.getOpenSpots());
    5656            if(k!=null){
    57                 response.put("success", "Internship edited successfully!");
    58                 return response;
     57                return new InternshipResponseDTO(k);
    5958            }
    6059        }
    6160
    62         response.put("error", "Internship edit failed!");
    63         return response;
     61        return new InternshipResponseDTO();
    6462    }
    6563
    6664    @PostMapping("/project/{id}")
    67     public Map<String, String> editProject(@PathVariable Long id,
    68                                           @RequestBody ProjectRegisterDTO body){
     65    public ProjectResponseDTO editProject(@PathVariable Long id,
     66                                          @RequestBody WorkEditDTO body){
    6967
    70         Map<String, String> response = new HashMap<>();
     68        Project p = this.workService.getProjectById(id);
    7169
    72         if(body.getAccountId().equals(this.workService.getProjectById(id).getAccount().getId())) {
     70        if(body.getAccountId().equals(p.getAccount().getId())) {
    7371            Project k = this.workService.editProject(id, body.getTitle(), body.getDescription(), body.getSalary());
    7472            if(k!=null){
    75                 response.put("success", "Project edited successfully!");
    76                 return response;
     73                return new ProjectResponseDTO(k);
    7774            }
    7875        }
    7976
    80         response.put("error", "Project edit failed!");
    81         return response;
     77        return new ProjectResponseDTO();
    8278    }
    8379}
Note: See TracChangeset for help on using the changeset viewer.